﻿
using System.Collections;
using TTQT.TTQT_Code;
namespace TTQT.Administration
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		Summary description for Log.
	/// </summary>
	public partial class Log : System.Web.UI.UserControl
	{
		private string month = null;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
//			visiblePanels(true,false);
//			btnDone.Enabled = false;
			BindDataMonth();
			if(!Page.IsPostBack)
			{
				visiblePanels(true,false,false,false,false);
			}
			
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{

		}
		#endregion

		private void visiblePanels(bool visiblePnlQuickSearch, bool visiblePnlAdvancedSearch, bool visiblePnlSrchByDate, bool visiblePnlSrchByTranID, bool visiblePnlResult)
		{
			this.pnlQuickSearch.Visible = visiblePnlQuickSearch;
			this.pnlAdvancedSearch.Visible = visiblePnlAdvancedSearch;
			this.pnlSrchByDate.Visible = visiblePnlSrchByDate;
			this.pnlSrchByTranID.Visible = visiblePnlSrchByTranID;
			this.PnlResult.Visible = visiblePnlResult;
		}

		protected void Calendar_SelectionChanged(object sender, System.EventArgs e)
		{
			
			lblInfo.Text = "Kết quả Log ngày " + Calendar.SelectedDate.Day.ToString() + " tháng " + Calendar.SelectedDate.Month.ToString() +
			               " nam " + Calendar.SelectedDate.Year.ToString();
		}

		private void btnDone_Click(object sender, System.EventArgs e)
		{
			
			dgLog.Enabled = true;
			bindGridLog();
		}

		private void bindGridLog()
		{
			try
			{
				dgLog.DataSource = DataAccessObject.instance().getLogByYearMonth(tbxYear.Text.Substring(2,2),ddlMonth.SelectedValue);
				dgLog.DataBind();
			}
			catch (Exception)
			{
			}
		}
		public void Grid_Change(Object sender, DataGridPageChangedEventArgs e) 
		{
 
			// Set CurrentPageIndex to the page the user clicked.
			dgLog.CurrentPageIndex = e.NewPageIndex;

			// Rebind the data to refresh the DataGrid control. 
			bindGridLog();
		}

		protected void btnContinue_Click(object sender, System.EventArgs e)
		{
		
		}

		protected void btnFinish_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("../Default.aspx");
		}
		private void BindDataMonth()
		{
			ArrayList arrList = new ArrayList();
			arrList.Add("1");
			arrList.Add("2");
			arrList.Add("3");
			arrList.Add("4");
			arrList.Add("5");
			arrList.Add("6");
			arrList.Add("7");
			arrList.Add("8");
			arrList.Add("9");
			arrList.Add("10");
			arrList.Add("11");
			arrList.Add("12");
			ddlMonth.DataSource = arrList;
			//ddlMonth.SelectedIndex = 0;
			ddlMonth.DataBind();
		}

		protected void btnQckSrch_Click(object sender, System.EventArgs e)
		{
			lblInfo.Text = "Kết quả Log tháng " + month+
				" năm " + tbxYear.Text.Substring(2,2);
			bindGridLog();
			visiblePanels(false, false, false, false, true);
		}

		protected void ddlMonth_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			month = ddlMonth.SelectedItem.Text;
		}	
	}
}
